package com.song.tools.songtest.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.song.tools.core.util.ObjectUtils;
import com.song.tools.mvc.manager.BaseManager;
import com.song.tools.songtest.beans.bo.SystemLogBo;
import com.song.tools.songtest.beans.query.SystemLogQuery;
import com.song.tools.songtest.convertor.SystemLogConvertor;
import com.song.tools.songtest.dao.entity.SystemLog;
import com.song.tools.songtest.dao.mapper.SystemLogMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 系统日志表 管理类
 * </p>
 *
 * @author song tools
 * @since 2024-07-16
 */
@Component
public class SystemLogManager extends BaseManager<SystemLog, SystemLogBo, SystemLogMapper, SystemLogQuery, Long, SystemLogConvertor> {

    @Resource
    private SystemLogConvertor systemLogConvertor;

    @Override
    public LambdaQueryWrapper<SystemLog> encapsulateQueryWrapper(SystemLogQuery query) {
        LambdaQueryWrapper<SystemLog> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getId()), SystemLog::getId, query.getId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogId()), SystemLog::getLogId, query.getLogId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestIp()), SystemLog::getRequestIp, query.getRequestIp());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogType()), SystemLog::getLogType, query.getLogType());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getDescription()), SystemLog::getDescription, query.getDescription());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getClassPath()), SystemLog::getClassPath, query.getClassPath());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getActionMethod()), SystemLog::getActionMethod, query.getActionMethod());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getHttpMethod()), SystemLog::getHttpMethod, query.getHttpMethod());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestParam()), SystemLog::getRequestParam, query.getRequestParam());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getResponseParam()), SystemLog::getResponseParam, query.getResponseParam());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestUri()), SystemLog::getRequestUri, query.getRequestUri());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getStartTimeStart()), SystemLog::getStartTime, query.getStartTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getStartTimeEnd()), SystemLog::getStartTime, query.getStartTimeEnd());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getEndTimeStart()), SystemLog::getEndTime, query.getEndTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getEndTimeEnd()), SystemLog::getEndTime, query.getEndTimeEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCostTime()), SystemLog::getCostTime, query.getCostTime());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getError()), SystemLog::getError, query.getError());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUser()), SystemLog::getCreateUser, query.getCreateUser());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SystemLog::getCreateUserId, query.getCreateUserId());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getCreateTimeStart()), SystemLog::getCreateTime, query.getCreateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getCreateTimeEnd()), SystemLog::getCreateTime, query.getCreateTimeEnd());

        return queryWrapper;
    }
}
